﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;

namespace Cookie_Hero
{
    class FPS
    {
        private SpriteFont spriteFont;
        private int frameRate = 0;
        private int frameCounter = 0;
        private TimeSpan elapsedTime = TimeSpan.Zero;

        public FPS (ContentManager content) {
            spriteFont = content.Load<SpriteFont>("fonts/Font");
        }

        public int update (GameTime gameTime) {
            ///////////////FPS/////////////////
            elapsedTime += gameTime.ElapsedGameTime;

            if (elapsedTime > TimeSpan.FromSeconds(1))
            {
                elapsedTime -= TimeSpan.FromSeconds(1);
                frameRate = frameCounter;
                frameCounter = 0;
            }
            return frameRate;
        }

        public void draw ( SpriteBatch spriteBatch ) {
            frameCounter++;
            spriteBatch.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend);
            spriteBatch.DrawString(spriteFont, frameRate.ToString(), Vector2.One, Color.White);
            spriteBatch.End();
        }

    }
}
